<template>
  <div>
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" :labelWidth="110"></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :selectionType="'single'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>
    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">取 消</el-button>
      <el-button @click="closeDrawer(2)" type="primary" :disabled="isOpen">确 定</el-button>
    </div>
  </div>
</template>
<script>
import { getmajorContract } from '@/api/omSale/KeyCustomers/OrderSubmission/index.js';
import { dictionary } from '@/utils/dictMixin';
export default {
  data() {
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchParams: {
        ownerCode: this.dealerCode
      },
      fetchApi: getmajorContract,
      selectList: [],
      isOpen: true
    };
  },
  mixins: [dictionary],
  props: ['dealerCode'],
  methods: {
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '合同名称',
          fieldName: 'contractName',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '项目名称',
          fieldName: 'projectName',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '大客户名称',
          fieldName: 'buyerName',
          placeholder: '请输入'
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '合同编号',
          dataIndex: 'contractNum',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '合同名称',
          dataIndex: 'contractName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '项目名称',
          dataIndex: 'projectName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '大客户名称',
          dataIndex: 'buyerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '合同生效日期',
          dataIndex: 'contractStartDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat:'yyyy-MM-dd'
        },
        {
          title: '交车类型',
          dataIndex: 'transportType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('2525'),
          render: p => {
            return <span>{this.createDictText(p.row.transportType, '2525')}</span>;
          }
        },
        {
          title: '订单总数量',
          dataIndex: 'totalNum',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '特殊约定',
          dataIndex: 'specialAgree',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    changeHandle(val) {
      this.isOpen = true;
      this.fetchParams = Object.assign({}, this.fetchParams, val);
    },
    closeDrawer(type) {
      if (type == 1) {
        this.$emit('close');
      } else {
        let json = this.selectList[0];
        this.$emit('close', json);
      }
    },
    selectChangeHandle(val) {
      if (val.length > 0) {
        this.selectList = val;
        this.isOpen = false;
      } else {
        this.selectList = [];
        this.isOpen = true;
      }
    }
  }
};
</script>
